# -*- encoding: utf-8 -*-

__author__ = 'shawhen'


class StdoutFile():
    """
    一个写入的数据会同时打印在标准输出的文件类
    """
    def __init__(self, path, mode):
        self._file = open(path, mode)

        self._print_from_write = False

    def write(self, data):
        if self._print_from_write is False:
            self._print_from_write = True
            print(data)
            self._file.write(data)
            self._print_from_write = False
        else:
            self._print_from_write = False

    def flush(self):
        self._file.flush()
